from PIL import Image
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QWidget
from src.forward.base.RightWidget import RightWidget
from src.forward.base.bean import forward, Table_ABC

@forward(name='审查试题')
class Correcting(RightWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("拖拽图片上传")
        self.setGeometry(100, 100, 800, 600)

        self.label = ImageDropLabel()
        self.label.setFixedHeight(100)
        layout = QVBoxLayout()
        layout.addWidget(self.label)

        self.topic_table=Table_ABC()
        layout.addWidget(self.topic_table)

        self.setLayout(layout)


class ImageDropLabel(QLabel):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setAcceptDrops(True)
        self.setAlignment(Qt.AlignCenter)
        self.setText("拖拽图片到这里")
        self.setStyleSheet("""
            QLabel {
                border: 2px dashed #aaa;
                font-size: 16px;
            }
        """)

    def dragEnterEvent(self, event):
        if event.mimeData().hasUrls():
            for url in event.mimeData().urls():
                file_path = url.toLocalFile()
                print(file_path)
            # 如果拖放的是图像数据




def dropEvent(self, event):
        if event.mimeData().hasImage():
            image = QPixmap(event.mimeData().imageData())
            print(image)
            self.setPixmap(image)
            event.acceptProposedAction()